import {
  PRODUCT_TYPE_OPTIONS,
  STOP_START_USEING_OPTIONS,
  LATENT_PRODUCT_TYPES_OPTIONS,
  PRODUCT_TYPES_ENUMS
} from '@/constants/commodity';
export const FORM_ITEMS = [
  {
    prop: 'enableStatus',
    label: '停/启状态：',
    type: 'select',
    options: STOP_START_USEING_OPTIONS,
    defaultVal: '1'
  },
  {
    prop: 'productKind',
    label: '商品大类',
    type: 'select',
    options: LATENT_PRODUCT_TYPES_OPTIONS,
    defaultVal: PRODUCT_TYPES_ENUMS.NORMAL
  },
  {
    prop: 'categoryPath',
    label: '分类：',
    type: 'input'
  },
  {
    prop: 'spuNo',
    label: 'SPU编码：',
    type: 'input'
  },
  {
    prop: 'skuNo',
    label: 'SKU编码：',
    type: 'input'
  },
  {
    prop: 'brandName',
    label: '商品品牌：',
    type: 'input'
  },
  {
    prop: 'productType',
    label: '商品类型：',
    type: 'select',
    clearable: true,
    options: PRODUCT_TYPE_OPTIONS
  },
  {
    prop: 'productName',
    label: '商品名称：',
    type: 'input'
  },
  {
    prop: 'relevantSupplyUuid',
    label: '供应商编码：',
    type: 'input'
  },
  {
    prop: 'manageAreaId',
    label: '商品管理区域',
    type: 'select',
    options: []
  },
  {
    prop: 'replaceSkuNo',
    label: '替代商品编码：',
    type: 'input'
  },
  {
    prop: 'specDetail',
    label: '规格：',
    type: 'input'
  }
];

const getStockColRender = (h, row, key, handleClick) => {
  if (row[key] <= 0) {
    return <span class="info__color">{row[key]}</span>
  }
  return <el-link
    type="primary"
    onClick = {() => { handleClick({ row, key }); }}
  >{ row[key] }</el-link>
}

const getReplaceProductColRender = (h, row, index, handleFocus) => {
  const inputComp = <el-input
    v-model={ row.replaceProductName }
    size="mini"
    suffix-icon="el-icon-search"
    onFocus={ () => { handleFocus({ index }) } }
  >
  </el-input>
  return inputComp;
}

export const getTableColumns = ({ handleViewStockInfo, handleSelectReplaceProduct, handleViewPlatformDetail }) => {
  const columns = [
    {
      title: '分类',
      key: 'categoryPath',
    },
    {
      title: 'SPU编码',
      key: 'spuNo'
    },
    {
      title: 'SKU编码',
      key: 'skuNo'
    },
    {
      title: '商品名称',
      key: 'productName'
    },
    {
      title: '管理区域',
      key: 'manageAreaName'
    },
    {
      title: '商品类型',
      key: 'productTypeStr'
    },
    {
      title: '规格',
      key: 'specDetailStr',
    },
    {
      title: '品牌',
      key: 'brandName'
    },
    {
      title: '停/启状态',
      key: 'enableStatusStr'
    },
    {
      title: '单据号',
      key: 'recordNo'
    },
    {
      title: '替代商品',
      width: 150,
      render: (h, { row, index }) => {
        return getReplaceProductColRender(h, row, index, handleSelectReplaceProduct);
      }
    },
    {
      title: '替代商品SKU编码',
      key: 'replaceSkuNo',
      width: 120
    },
    {
      title: '近1年销量',
      key: 'sales',
      width: 100,
      sortable: true
    },
    {
      title: '上次停用原因',
      key: 'reasonTypeStr',
      width: 120
    },
    {
      title: '商品准入时间',
      key: 'prepareTime',
      width: 120
    },
    {
      title: '审核状态',
      key: 'auditStateStr'
    },
    {
      title: '实物库存数',
      key: 'allRealStockNum',
      width: 120,
      sortable: true,
      render: (h, { row }) => {
        return getStockColRender(h, row, 'allRealStockNum', handleViewStockInfo);
      }
    },
    {
      title: '采购在途数',
      key: 'allPurchaseStockNum',
      width: 120,
      sortable: true,
      render: (h, { row }) => {
        return getStockColRender(h, row, 'allPurchaseStockNum', handleViewStockInfo);
      }
    },
    {
      title: '销售占用数',
      key: 'allRealStockOccupy',
      width: 120,
      sortable: true,
      render: (h, { row }) => {
        return getStockColRender(h, row, 'allRealStockOccupy', handleViewStockInfo);
      }
    },
    {
      title: '转货在途数',
      key: 'allTransshipStockNum',
      width: 120,
      sortable: true,
      render: (h, { row }) => {
        return getStockColRender(h, row, 'allTransshipStockNum', handleViewStockInfo);
      }
    },
    {
      title: '客户平台是否允许停用',
      key: 'platformEnableStopStr',
      width: 160,
      sortable: true,
    },
    {
      title: '客户平台明细',
      key: 'platformDetail',
      width: 120,
      sortable: true,
      render: (h, { row }) => getStockColRender(h, row, 'platformDetail', handleViewPlatformDetail)
    }
  ];
  return columns;
}
